
**** Returns to Scale from Labor Specialization: Evidence from Asset Management Mergers (Luo, Manconi and Schumacher) *************
*Purpose: Generate Figure 2, Tables 1C, 2, 3, 4， 6, 7, 8 and 9

**Define macros 
global controls "firmsize fundsize expenses volatility pastreturn" 
global cluster "deal_id time"
global basefe "deal_id#pair#fundid deal_id#pair#time"

**Load data
clear all
use "$datapath\matchingsample_fundlevel.dta"

**-------------------Figure 2A-------------------**
reghdfe internalnewmanager treat_f2event treat_f1event treat_l1event treat_l2event treat_l3event treat_f3event $controls if matchingfundsample == 1 , a($basefe) cluster($cluster)
estimates store reg     
test treat_f3event+treat_f2event + treat_f1event = treat_l1event+treat_l2event+treat_l3event
local p = trim("`: display %10.3f r(p)'")

coefplot reg, vert keep(treat_f3event treat_f2event treat_f1event treat_l1event treat_l2event treat_l3event) order(treat_f3event $treatevtlist) omitted ///
                  xline(4, lwidth(6) lcolor(gs14)) ///
				  note({stSerif: P-value (post-pre) = `p'}) ///
                  xlabel(, add labsize(small)) ylabel(, noticks add labsize(small)) ///
                  xtitle({stSerif: Event time (in years)}, tstyle(size(normal))) ///
                  recast(line) level(95) graphregion(color(white) lwidth(medium)) ///
                  ytitle({stSerif: Internal New Manager}, tstyle(size(normal)))
graph export "$outputpath/Figure2A.jpg", as(jpg) replace

**-------------------Figure 2B-------------------**
reghdfe externalnewmanager treat_f2event treat_f1event treat_l1event treat_l2event treat_l3event treat_f3event $controls if matchingfundsample == 1 , a($basefe) cluster($cluster)
estimates store reg     
test treat_f3event+treat_f2event + treat_f1event = treat_l1event+treat_l2event+treat_l3event
local p = trim("`: display %10.3f r(p)'")

coefplot reg, vert keep(treat_f3event treat_f2event treat_f1event treat_l1event treat_l2event treat_l3event) order(treat_f3event $treatevtlist) omitted ///
                  xline(4, lwidth(6) lcolor(gs14)) ///
				  note({stSerif: P-value (post-pre) = `p'}) ///
                  xlabel(, add labsize(small)) ylabel(, noticks add labsize(small)) ///
                  xtitle({stSerif: Event time (in years)}, tstyle(size(normal))) ///
                  recast(line) level(95) graphregion(color(white) lwidth(medium)) ///
                  ytitle({stSerif: External New Manager}, tstyle(size(normal)))
graph export "$outputpath/Figure2B.jpg", as(jpg) replace


**-------------------Table 1, Panel C -------------------**
capture drop in_sample
gen in_sample=1
foreach var in $controls{
replace in_sample=0 if `var'==.
}
// summary statistics for treated funds with available information in the control variables
estpost tabstat firmsize_billion fundsize_million expenses volatility fundage pastreturn num_managers if treat == 1 & in_sample == 1 , stat(mean sd p5 p25 p50 p75 p95) col(stat)  
eststo stat

esttab stat using "$outputpath/Table1AC.rtf", append ///
nolines label nomtitle nonumber nonote noobs ///
cells(" mean(fmt(%9.2fc)) sd(fmt(%9.2fc)) p5(fmt(%9.2fc)) p25(fmt(%9.2fc)) p50(fmt(%9.2fc)) p75(fmt(%9.2fc)) p95(fmt(%9.2fc))") collabels(none) 


**-------------------Table 2-------------------**

**1. Matching funds
// create return variables in percentage 
foreach n of varlist netofstyleret capmalpha ff4falpha mktadj_ret dgtw_ret etfadj_ret{
	gen `n'_perc = `n' * 100
}

//Compare treated and matching funds in the one year prior to mergers 
capture drop in_sample
gen in_sample=1
foreach var in logfirmsize_billion logfundsize_million{
replace in_sample=0 if `var'==.
}

gen control = 1-treat

qui foreach m of varlist netofstyleret_perc capmalpha_perc ff4falpha_perc mktadj_ret_perc dgtw_ret_perc etfadj_ret_perc valueadded logfirmsize_billion logfundsize_million expenses volatility pastreturn{

** Columns 1 and 2
 reg `m' treat control if post == 0 & eventtime >=-2 & in_sample == 1 , noc cluster(fundstyle)
estimates store `m'
scalar define t0_`m' = _b[control]
scalar define t1_`m' = _b[treat]

** Columns 3 and 4
 reg `m' treat if post == 0 & eventtime >=-2 & in_sample == 1 , cluster(fundstyle)
estimates store `m'
scalar define dif_`m' = _b[treat]
scalar define t_`m' = _b[treat]/_se[treat]
}

log using "$outputpath/Table2.log", replace
foreach m of varlist netofstyleret_perc capmalpha_perc ff4falpha_perc mktadj_ret_perc dgtw_ret_perc etfadj_ret_perc valueadded logfirmsize_billion logfundsize_million expenses volatility pastreturn{
disp as text " `m' " as result %7.2f t1_`m' ///
as text "    " as result %7.2f t0_`m' ///
as text "    " as result %7.2f dif_`m' ///
as text "    " as result %7.2f t_`m'
}
log close

**2. Withdrawn deals 
clear all
use "$datapath\withdrawndeals.dta"

capture drop in_sample
gen in_sample=1
foreach var in logfirmsize_billion logfundsize_million{
replace in_sample=0 if `var'==.
}
foreach n of varlist netofstyleret capmalpha ff4falpha mktadj_ret dgtw_ret etfadj_ret{
	gen `n'_perc = `n' * 100
}

gen control = 1-treat

qui foreach m of varlist netofstyleret_perc capmalpha_perc ff4falpha_perc mktadj_ret_perc dgtw_ret_perc etfadj_ret_perc valueadded logfirmsize_billion logfundsize_million expenses volatility pastreturn{

** Columns 1 and 2
 reg `m' treat control if post == 0 & eventtime >=-2 & in_sample == 1 , noc cluster(fundstyle)
estimates store `m'
scalar define t0_`m' = _b[control]
scalar define t1_`m' = _b[treat]

** Columns 3 and 4
 reg `m' treat if post == 0 & eventtime >=-2 & in_sample == 1 , cluster(fundstyle)
estimates store `m'
scalar define dif_`m' = _b[treat]
scalar define t_`m' = _b[treat]/_se[treat]
}

log using "$outputpath/Table2.log", append
foreach m of varlist netofstyleret_perc capmalpha_perc ff4falpha_perc mktadj_ret_perc dgtw_ret_perc etfadj_ret_perc valueadded logfirmsize_billion logfundsize_million expenses volatility pastreturn{
disp as text " `m' " as result %7.2f t1_`m' ///
as text "    " as result %7.2f t0_`m' ///
as text "    " as result %7.2f dif_`m' ///
as text "    " as result %7.2f t_`m'
}
log close


**-------------------Table 3-------------------**
clear all
use "$datapath\matchingsample_fundlevel.dta"

// columns 1 to 3
qui foreach n in allnewmanager internalnewmanager externalnewmanager{
reghdfe `n' c.treat##c.post $controls if matchingfundsample == 1, a($basefe) cluster($cluster)
estadd local deal_pair_fund Y 
estadd local deal_pair_time Y 
estadd local ctrl Y
estimates store `n'
}

// column 4
*add withdrawn sample 
append using "$datapath\withdrawndeals.dta"
reghdfe internalnewmanager c.treat##c.post $controls if matchingfundsample == 0, a($basefe) cluster($cluster)
estadd local deal_pair_fund Y 
estadd local deal_pair_time Y 
estadd local ctrl Y
estimates store withdrawn

esttab allnewmanager externalnewmanager internalnewmanager withdrawn using "$outputpath/Table3.rtf", replace ///
keep(c.treat#c.post $controls) order(c.treat#c.post $controls) ///
b(%5.3f) t(%5.2f) nolines noeqlines nolabel nogaps ///
stats( deal_pair_fund deal_pair_time ctrl r2 N, fmt(0 0 0 3 %9.0gc)) ///
starlevels(* 0.10 ** 0.05 *** 0.01) nonotes varwidth(15) modelwidth(10) noomitted 

// drop withdrawn deals afterwards 
drop if matchingfundsample == 0

**-------------------Table 4-------------------**
qui reghdfe allnewmanager c.treat##c.post##c.largedelta $controls, a($basefe) cluster($cluster)
estadd local deal_pair_fund Y 
estadd local deal_pair_time Y 
estadd local ctrl Y
estimates store delta

qui foreach ct in 1 0{
reghdfe allnewmanager c.treat##c.post##c.generalist $controls if largedelta == `ct', a($basefe) cluster($cluster)
estadd local deal_pair_fund Y 
estadd local deal_pair_time Y 
estadd local ctrl Y
estimates store delta`ct'
}

esttab delta delta1 delta0 using "$outputpath/Table4.rtf", replace ///
keep(c.treat#c.post#c.largedelta c.treat#c.post#c.generalist c.treat#c.post) ///
order(c.treat#c.post#c.largedelta c.treat#c.post#c.generalist c.treat#c.post) ///
b(%5.3f) t(%5.2f) nolines noeqlines nolabel nogaps ///
stats(deal_pair_fund deal_pair_time ctrl r2 N, fmt(0 0 0 3 %9.0gc)) ///
starlevels(* 0.10 ** 0.05 *** 0.01) nonotes varwidth(15) modelwidth(10) noomitted 


**-------------------Table 6-------------------**
qui foreach var in netofstyleret capmalpha ff4falpha mktadj_ret dgtw_ret etfadj_ret{
reghdfe `var' c.treat##c.post##c.largedelta $controls, a($basefe) cluster($cluster)
estadd local deal_pair_fund Y 
estadd local deal_pair_time Y 
estadd local ctrl Y
estimates store `var'
}

esttab  netofstyleret capmalpha ff4falpha mktadj_ret dgtw_ret etfadj_ret using "$outputpath/Table6.rtf", replace ///
keep(c.treat#c.post#c.largedelta c.treat#c.post) ///
order(c.treat#c.post#c.largedelta c.treat#c.post) ///
b(%5.3f) t(%5.2f) nolines noeqlines nolabel nogaps ///
stats(deal_pair_fund deal_pair_time ctrl r2 N, fmt(0 0 0 3 %9.0gc)) ///
starlevels(* 0.10 ** 0.05 *** 0.01) nonotes varwidth(15) modelwidth(10) noomitted 


**-------------------Table 7-------------------**
qui foreach ct in 1 0 {
reghdfe etfadj_ret c.treat##c.post##c.generalist $controls if largedelta == `ct', ///
a($basefe)  cluster($cluster)
estadd local deal_pair_fund Y 
estadd local deal_pair_time Y 
estadd local ctrl Y
estimates store x_`ct'
}

esttab x_1 x_0 using "$outputpath/Table7.rtf", replace ///
keep(c.treat#c.post#c.generalist c.treat#c.post) ///
order(c.treat#c.post#c.generalist c.treat#c.post) ///
b(%5.3f) t(%5.2f) nolines noeqlines nolabel nogaps ///
stats(deal_pair_fund deal_pair_time ctrl r2 N, fmt(0 0 0 3 %9.0gc)) ///
starlevels(* 0.10 ** 0.05 *** 0.01) nonotes varwidth(15) modelwidth(10) noomitted 


**-------------------Table 8-------------------**

**Row 1
preserve 
keep if treat == 1 & valueadded<.
gen pre = 1 - post

**sum deal-level value added by time, and count the number of deals and funds that are used to calculate the value added
collapse (sum) valueadded (count) nooffunds = fundid, by(deal_id eventtime post pre)
collapse (sum) valueadded nooffunds (count) noofdeals = deal_id , by(eventtime post pre)
gen valueadded_perdeal = valueadded/noofdeal
gen valueadded_perfund = valueadded/nooffunds

qui reg valueadded_perdeal post pre , noc robust
estimates store x1

qui reg valueadded_perdeal post , robust
estimates store x2

qui reg valueadded_perfund post , robust
estimates store x3

esttab x1 x2 x3 using "$outputpath/Table8.rtf", replace ///
keep(post pre) order(post pre ) ///
b(%5.3f) t(%5.2f) nolines noeqlines nolabel nogaps noobs ///
starlevels(* 0.10 ** 0.05 *** 0.01) nonotes varwidth(15) modelwidth(10) noomitted 
restore 

**Rows 2 - 3
preserve 
keep if treat == 1 & valueadded<.
gen pre = 1 - post

collapse (sum) valueadded (count) nooffunds = fundid, by(deal_id eventtime largedelta post pre)
collapse (sum) valueadded nooffunds (count) noofdeals = deal_id , by(eventtime largedelta post pre)
gen valueadded_perdeal = valueadded/noofdeal
gen valueadded_perfund = valueadded/nooffunds

qui foreach k in 1 0{
 reg valueadded_perdeal post pre if largedelta == `k', noc robust
estimates store x1

 reg valueadded_perdeal post if largedelta == `k', robust
estimates store x2

 reg valueadded_perfund post if largedelta == `k', robust
estimates store x3

esttab x1 x2 x3 using "$outputpath/Table8.rtf", append ///
keep(post pre) order(post pre ) ///
b(%5.3f) t(%5.2f) nolines noeqlines nolabel nogaps noobs ///
starlevels(* 0.10 ** 0.05 *** 0.01) nonotes varwidth(15) modelwidth(10) noomitted 
}
restore 

**Rows 4 - 5
preserve 
keep if treat == 1 & valueadded<.
gen pre = 1 - post

collapse (sum) valueadded (count) nooffunds = fundid, by(deal_id eventtime generalist post pre)
collapse (sum) valueadded nooffunds (count) noofdeals = deal_id , by(eventtime generalist post pre)
gen valueadded_perdeal = valueadded/noofdeal
gen valueadded_perfund = valueadded/nooffunds

qui foreach k in 1 0{
 reg valueadded_perdeal post pre if generalist == `k', noc robust
estimates store x1

 reg valueadded_perdeal post if generalist == `k', robust
estimates store x2

 reg valueadded_perfund post if generalist == `k', robust
estimates store x3

esttab x1 x2 x3 using "$outputpath/Table8.rtf", append ///
keep(post pre) order(post pre ) ///
b(%5.3f) t(%5.2f) nolines noeqlines nolabel nogaps noobs ///
starlevels(* 0.10 ** 0.05 *** 0.01) nonotes varwidth(15) modelwidth(10) noomitted 
}
restore 

**Rows 6 - 9
preserve 
keep if treat == 1 & valueadded<.
gen pre = 1 - post

collapse (sum) valueadded (count) nooffunds = fundid, by(deal_id eventtime generalist largedelta post pre)
collapse (sum) valueadded nooffunds (count) noofdeals = deal_id , by(eventtime generalist largedelta post pre)
gen valueadded_perdeal = valueadded/noofdeal
gen valueadded_perfund = valueadded/nooffunds

qui foreach g in 1 0{
qui foreach k in 1 0{
 reg valueadded_perdeal post pre if generalist == `g' & largedelta == `k', noc robust
estimates store x1

 reg valueadded_perdeal post if generalist == `g' & largedelta == `k', robust
estimates store x2

 reg valueadded_perfund post if generalist == `g' & largedelta == `k', robust
estimates store x3

esttab x1 x2 x3 using "$outputpath/Table8.rtf", append ///
keep(post pre) order(post pre ) ///
b(%5.3f) t(%5.2f) nolines noeqlines nolabel nogaps noobs ///
starlevels(* 0.10 ** 0.05 *** 0.01) nonotes varwidth(15) modelwidth(10) noomitted 
}
}
restore 

**-------------------Table 9-------------------**

**Panel A
qui foreach var in activeshare_exparea activeshare_nonexparea ici_exparea ici_nonexparea distancetopeers_exparea distancetopeers_nonexparea{
qui reghdfe `var' c.treat##c.post##c.largedelta $controls, a($basefe) cluster($cluster)
estadd local deal_pair_fund Y 
estadd local deal_pair_time Y 
estadd local ctrl Y
estimates store `var'
}

esttab activeshare_exparea  ici_exparea distancetopeers_exparea activeshare_nonexparea ici_nonexparea  distancetopeers_nonexparea using "$outputpath/Table9.rtf", replace ///
keep(c.treat#c.post#c.largedelta c.treat#c.post) ///
order(c.treat#c.post#c.largedelta c.treat#c.post) ///
b(%5.3f) t(%5.2f) nolines noeqlines nolabel nogaps ///
stats(deal_pair_fund deal_pair_time ctrl r2 N, fmt(0 0 0 3 %9.0gc)) ///
starlevels(* 0.10 ** 0.05 *** 0.01) nonotes varwidth(15) modelwidth(10) noomitted 

**Panel B
qui foreach var in mktadj_ret_exparea mktadj_ret_nonexparea dgtw_ret_exparea dgtw_ret_nonexparea etfadj_ret_exparea etfadj_ret_nonexparea{
qui reghdfe `var' c.treat##c.post##c.largedelta $controls, a($basefe) cluster($cluster)
estadd local deal_pair_fund Y 
estadd local deal_pair_time Y 
estadd local ctrl Y
estimates store `var'
}

esttab mktadj_ret_exparea  dgtw_ret_exparea etfadj_ret_exparea mktadj_ret_nonexparea dgtw_ret_nonexparea  etfadj_ret_nonexparea using "$outputpath/Table9.rtf", append ///
keep(c.treat#c.post#c.largedelta c.treat#c.post) ///
order(c.treat#c.post#c.largedelta c.treat#c.post) ///
b(%5.3f) t(%5.2f) nolines noeqlines nolabel nogaps ///
stats(deal_pair_fund deal_pair_time ctrl r2 N, fmt(0 0 0 3 %9.0gc)) ///
starlevels(* 0.10 ** 0.05 *** 0.01) nonotes varwidth(15) modelwidth(10) noomitted 



